#ifndef VERTEX_ACCESSOR_HPP
#define VERTEX_ACCESSOR_HPP
#include "GeometryTypes.hpp"
#include <boost/signal.hpp>

class VertexAccessor
{
   public:
   
      VertexAccessor(VertexList* aVertexList) : mVerts(aVertexList) {}
   
      const Vec3& operator[](int aIndex) const
      {
         if (mVerts != 0)
         {
            return (*mVerts)[aIndex];
         }
         else
         {
            static Vec3 v;
            return v;
         }
      }
      
      VertexList& Get()
      {
         if (mVerts) return (*mVerts);
         static VertexList v;
         return v;
      }
      
      void Set(int aIndex, const Vec3& aVec)
      {
         if (mVerts != 0)
         {
            (*mVerts)[aIndex] = aVec;
            VertexMoved(aIndex);
         }
      }
      
      boost::signal<void(int)> VertexMoved;
      
      boost::signal<void(int)> VertexErased;

      boost::signal<void()> ListUpdated;
      
      
      size_t size() const { if (mVerts) return mVerts->size(); else return 0; }
      
      bool IsValid() const { return mVerts != 0; }
      
      void SetVertexList(VertexList* aVertexList) { mVerts = aVertexList; }
      
   private:
   
      VertexList* mVerts;
};
#endif
